﻿using DynamicViewFormLibrary;
using DynamicViewFormLibrary.Utils;
using System;
using System.IO;
using System.Text;
using System.Windows.Forms;

namespace DynamicViewFormApp
{
    public partial class ObjectiveItemForm : Form
    {

        public ObjectiveItemForm()
        {
            InitializeComponent();
        }

        private void BtnPreView_Click(object sender, EventArgs e)
        {
            string itemChoices = textBox_itemChoices.Text.Trim();
            int itemNum = (int)numericUpDown_itemNum.Value;
            int itemStart = (int)numericUpDown_itemStart.Value;
            int itemOrientation = comboBox_itemOrientation.SelectedIndex;

            string filePath = RtfGenerater.GeneraterObjectItem(itemChoices, itemOrientation, itemNum, itemStart);

            rtb.LoadFile(filePath);
            rtb.Rtf = rtb.Rtf.Replace("\\'cb\\'ce\\'cc\\'e5", "");
            rtb.Rtf = rtb.Rtf.Replace("\\clvertalc", "\\clvertalc\\clbrdrl\\brdrw10\\brdrs\\clbrdrt\\brdrw10\\brdrs\\clbrdrr\\brdrw10\\brdrs\\clbrdrb\\brdrw10\\brdrs ");
            rtb.Rtf = rtb.Rtf.Replace("\\cf1", "\\cf0");//选项颜色
            rtb.SelectAll();
            rtb.SelectionAlignment = HorizontalAlignment.Center;
            rtb.SelectionLength = 0;

            FilePathUtil.DeleteFile(filePath);//删除过程文件
        }

        private void ObjectiveItemForm_Load(object sender, EventArgs e)
        {
            comboBox_itemOrientation.SelectedIndex = 0;
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            MainForm mainForm = (MainForm)this.Owner;//获取拥有此窗体的窗体
            rtb.SelectAll();
            rtb.Copy();
            rtb.SelectionLength = 0;
            mainForm.PasteContent();//插入剪贴板内容
            this.Close();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
